<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import = "com.classes.Casemast, java.util.ArrayList, java.util.TreeMap, org.owasp.encoder.Encode" %>
<%@ page import = "com.mbbmap.security.dao.*" %>
<%@ include file="/jsp/map/include/user-dao.jsp" %>	
<%@page import="com.mbbmap.util.EncryptionHelper"%>
<%

TreeMap<String, String> search = (TreeMap<String, String>) request.getAttribute("search");

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/jsp/map/include/html-meta.jsp" />
<title>MAYBANK</title>
<script src="<%= request.getContextPath() %>/js/report.js"></script>
</head>

<body onload="report.report_init();">

<!-- Header -->
<%@ include file="/jsp/common/Header.jsp" %>	
<!-- End Header -->


<div class="row-fluid page">
	<div class="span12">
		
		<jsp:include page="/jsp/map/include/report-nav.jsp">
			<jsp:param name="report_title" value='<%=EncryptionHelper.encrypt("Exceptional Report") %>' />
		</jsp:include>

		<form name="search_form" method="post" action="<%= request.getContextPath() + "/Report.do?dispatch=exceptional_report" %>" onsubmit="return report.search_status_validate();">
			<div class="row-fluid form-horizontal search">
				<div class="span6">
				
					<div class="control-group">
						<label class="control-label">Application Type</label>
						<div class="controls">
							<select id="application_type" name="application_type">
							<% 
								String html = "<option value=\"\"></option>"
									+ "<option value=\"New Application\">New Application</option>"
									+ "<option value=\"Extend Facility\">Extend Facility</option>"
									+ "<option value=\"e-Commerce/M2u\">e-Commerce/M2u</option>"
									+ "<option value=\"Additional Terminal/mPOS Reader\">Additional Terminal/mPOS Reader</option>";
								
								if(search.containsKey("application_type") && search.get("application_type").length() > 0){
									html = html.replace("value=\"" + search.get("application_type") + "\"", "value=\"" + search.get("application_type") + "\" selected ");
								}
								
								out.println(html);
							%>
							</select>
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">Region</label>
						<div class="controls">
							<select id="reseller_location" name="reseller_location">
							<% 
								html = "<option value=\"\"></option>"
									+ "<option value=\"SABAH\">SABAH</option>"
									+ "<option value=\"SARAWAK\">SARAWAK</option>"
									+ "<option value=\"PERLIS\">PERLIS</option>"
									+ "<option value=\"KEDAH\">KEDAH</option>"
									+ "<option value=\"PULAU PINANG\">PULAU PINANG</option>"
									+ "<option value=\"PERAK\">PERAK</option>"
									+ "<option value=\"KELANTAN\">KELANTAN</option>"
									+ "<option value=\"TERENGGANU\">TERENGGANU</option>"
									+ "<option value=\"PAHANG\">PAHANG</option>"
									+ "<option value=\"SELANGOR\">SELANGOR</option>"
									+ "<option value=\"NEGERI SEMBILAN\">NEGERI SEMBILAN</option>"
									+ "<option value=\"MELAKA\">MELAKA</option>"
									+ "<option value=\"JOHOR\">JOHOR</option>"
									+ "<option value=\"WILAYAH PERSEKUTUAN\">WILAYAH PERSEKUTUAN</option>";
								
								if(search.containsKey("reseller_location") && search.get("reseller_location").length() > 0){
									html = html.replace("value=\"" + search.get("reseller_location") + "\"", "value=\"" + search.get("reseller_location") + "\" selected ");
								}
								
								out.println(html);
							%>
							</select>
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">Monthly</label>
						<div class="controls">
							<%
							html = "";
							if(search.containsKey("year")){
								html = search.get("year");
							}
							%>
							<input type="text" id="year" name="year" placeholder="eg. 2015" value="<%= html %>" />
							
							<select id="month" name="month">
							<% 
								html = "<option value=\"\"></option>"
									+ "<option value=\"01\">JANUARY</option>"
									+ "<option value=\"02\">FEBRUARY</option>"
									+ "<option value=\"03\">MARCH</option>"
									+ "<option value=\"04\">APRIL</option>"
									+ "<option value=\"05\">MAY</option>"
									+ "<option value=\"06\">JUNE</option>"
									+ "<option value=\"07\">JULY</option>"
									+ "<option value=\"08\">AUGUST</option>"
									+ "<option value=\"09\">SEPTEMBER</option>"
									+ "<option value=\"10\">OCTOBER</option>"
									+ "<option value=\"11\">NOVEMBER</option>"
									+ "<option value=\"12\">DECEMBER</option>";
									
								if(search.containsKey("month") && search.get("month").length() > 0){
									html = html.replace("value=\"" + search.get("month") + "\"", "value=\"" + search.get("month") + "\" selected ");
								}
								
								out.println(html);
							%>
							</select>
						</div>
					</div>
					
				</div>
				
				<div class="span6">
					
					<div class="control-group">
						<label class="control-label">&nbsp</label>
						<div class="controls">
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">Group</label>
						<div class="controls">
							<select id="group_code" name="group_code">
							<% 
								html = "<option value=\"\"></option>";
								for(SecGroupsDao ug : (ArrayList<SecGroupsDao>) request.getAttribute("groupList")){
									html += "<option value=\"" + ug.getGroupCode() + "\">" + ug.getGroupName() + "</option>";
								}
								
								if(search.containsKey("group_code") && search.get("group_code").length() > 0){
									html = html.replace("value=\"" + search.get("group_code") + "\"", "value=\"" + search.get("group_code") + "\" selected ");
								}
								
								out.println(html);
							%>
							</select>
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">Daily</label>
						
						<div class="controls">
							<%
							html = "";
							if(search.containsKey("from_date")){
								html = search.get("from_date");
							}
							%>
							<input type="text" id="from_date" name="from_date" placeholder="eg. 23/01/2015" value="<%= html %>" />
							
							<%
							html = "";
							if(search.containsKey("to_date")){
								html = search.get("to_date");
							}
							%>
							<input type="text" id="to_date" name="to_date" placeholder="eg. 09/02/2015" value="<%= html %>" />
						</div>
					</div>
					
				</div>
			</div>
			
			<div class="row-fluid">
				<div class="span12 btn-control search">
					<button id="search_submit" name="search_submit" type="submit" class="btn">Search</button>
					<button id="search_clear" name="search_clear" type="submit" class="btn">Clear</button>
					<button id="export_submit" name="export_submit" type="submit" class="btn">Export</button>
				</div>
			</div>
			
		</form>
		
		<table class="tblDetails"><thead>
			<tr>
				<th>No.</th>
				<th>MAP Reference No.</th>
				<th>Application Type</th>
				<th>Submission Date</th>
				<th>Matrix & Non Matrix Transition</th>
				<th>Group Name</th>
				<th>Creator</th>
				<th>Region (Maxis)</th>
				<th>Status</th>
			</tr>
		</thead><tbody>
		<%
			int n = 0;
			for(TreeMap<String, String> c : (ArrayList<TreeMap<String, String>>) request.getAttribute("cArr")){
				//String case_url = request.getContextPath() + "/NewApp.do?dispatch=init&m_id=" + c.getMerchant().getId() + "&c_id=" + c.getId();
				
				html = "<tr class=" + (n % 2 > 0 ? "alt" : "even") + ">"
				+ "	<td>" + (n+1) + "</td>"
				+ "	<td>" + (c.get("map_ref_no") != null ? Encode.forHtml(c.get("map_ref_no")) : "") + "</td>"
				+ "	<td>" + (c.get("application_type") != null ? Encode.forHtml(c.get("application_type")) : "") + "</td>"
				+ "	<td>" + (c.get("created_date") != null ? Encode.forHtml(c.get("created_date")) : "") + "</td>"
				+ "	<td>" + (c.get("matrix") != null ? Encode.forHtml(c.get("matrix")) : "") + "</td>"
				+ "	<td>" + (c.get("group_code") != null ? Encode.forHtml(c.get("group_code")) : "") + "</td>"
				+ "	<td>" + (c.get("creator") != null ? Encode.forHtml(c.get("creator")) : "") + "</td>"
				+ "	<td>" + (c.get("region") != null ? Encode.forHtml(c.get("region")) : "") + "</td>"
				+ "	<td>" + (c.get("status") != null ? Encode.forHtml(c.get("status")) : "") + "</td>"
				+ "</tr>";
				
				out.println(html);
				++n;
			}
		%>
		</tbody></table>
		
		<table class="tblDetails"><thead>
			<tr>
				<th>Status</th>
				<th>Total Applications</th>
			</tr>
		</thead><tbody>
		<%
			int grand_total = 0;
			int n2 = 0;
			
			for(TreeMap<String, String> Summ : (ArrayList<TreeMap<String, String>>) request.getAttribute("cSumm")){
				//String case_url = request.getContextPath() + "/NewApp.do?dispatch=init&m_id=" + c.getMerchant().getId() + "&c_id=" + c.getId();
				
				html = "<tr class=" + (n2 % 2 > 0 ? "alt" : "even") + ">"
				+ "	<td>" + (Summ.get("status") != null ? Encode.forHtml(Summ.get("status")) : "") + "</td>"
				+ "	<td>" + (Summ.get("total") != null ? Encode.forHtml(Summ.get("total")) : "") + "</td>"
				+ "</tr>";
				
				out.println(html);
				grand_total = grand_total + Integer.parseInt(Summ.get("total"));
				++n2;
			}
			
			String last_line = "<tr class=" + (n2 % 2 > 0 ? "alt" : "even") + ">"
								+ "<td><b>Grand Total</b></td>"
								+ "<td><b>" + grand_total + "</b></td>"
								+ "</tr>";
			out.println(last_line);
		%>
		</tbody></table>
		
	</div>
</div>

<!-- Footer -->
<%@ include file="/jsp/common/Footer.jsp" %>	
<!-- End Footer -->


</body>
</html>